Make pocketfms reader more robust on a waypoint name with a space in it
authorrobertlipe <robertlipe@gmail.com>
Sat, 8 Dec 2012 08:27:32 +0000 (08:27 +0000)
committerrobertlipe <robertlipe@gmail.com>
Sat, 8 Dec 2012 08:27:32 +0000 (08:27 +0000)
and make the writer not include a space.

gpsbabel/pocketfms_wp.c

index 8f53fed63b5c9c7a5834e06367a82dcfecdce888..a43dce3fba43686394e481a3d022b0ad538de65a 100644 (file)
@@ -68,10 +68,20 @@ data_read(void)
     wpt = waypt_new();
     s = buff;
     s = csv_lineparse(s, "\\w", "", linecount);
+    if (!s) {
+      fatal(MYNAME "Invalid name");
+    }
     wpt->shortname = xstrdup(s);
     s = csv_lineparse(NULL, "\\w", "", linecount);
+    if (!s) {
+      fatal(MYNAME "Invalid latitude %s", wpt->shortname);
+    }
     wpt->latitude = wppos_to_dec(s);
+
     s = csv_lineparse(NULL, "\\w", "", linecount);
+    if (!s) {
+      fatal(MYNAME "Invalid longitude %s", wpt->shortname);
+    }
     wpt->longitude = wppos_to_dec(s);
     waypt_add(wpt);
   }
@@ -92,7 +102,24 @@ wr_init(const char *fname)
 static void
 enigma_waypt_disp(const waypoint *wpt)
 {
-  gbfprintf(file_out, "%s %f %f\n", wpt->shortname, wpt->latitude, wpt->longitude);
+  char *t;
+  if (wpt->shortname) {
+    // The output might have a space or control character.
+    int i, l = strlen(wpt->shortname);
+    t = xmalloc(l);
+    char *d = t;
+    for (i = 0; i < l; i++) {
+      char s = wpt->shortname[i];
+      if(isgraph(s)) {
+        *d++ = s;
+      }
+    }
+    *d = 0;
+  } else {
+    t = xstrdup("NONAME");
+  }
+  gbfprintf(file_out, "%s %f %f\n", t, wpt->latitude, wpt->longitude);
+  xfree(t);
 }
 
 static void